﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using BLToolkit.Data;
using BLToolkit.Data.Linq;

namespace DAL
{
    public class TKDoanhThuRepository : ITKDoanhThuRepository
    {
        private DbManager db = null;
        public TKDoanhThuRepository()
        {
            db=new DbManager("QuanLyBilliards");
        }

        public IQueryable<TKDoanhThu> GetAll()
        {
     
            return db.GetTable<TKDoanhThu>();
        }

        public IQueryable<TKDoanhThu> GetByNam(string nam)
        {
            return db.GetTable<TKDoanhThu>().Where(tk => tk.ThoiGianTK== nam);
        }

        public IQueryable<TKDoanhThu> GetByThang(string thang)
        {
            return db.GetTable<TKDoanhThu>().Where(tk => tk.ThoiGianTK.ToString().Substring(tk.ThoiGianTK.ToString().Length - 7, 7) == thang);
        }
        //ham nay sai ui,chac t ko co dl nen vay,de  tao chay thu
        public IQueryable<TKDoanhThu> GetByQuy(string quy)
        {
            return db.GetTable<TKDoanhThu>().Where(tk => tk.ThoiGianTK == quy);
        }

        public TKDoanhThu GetByNgay(string ngay)
        {
            return db.GetTable<TKDoanhThu>().SingleOrDefault(tk => tk.ThoiGianTK == ngay);
        }


        public void AddNew(TKDoanhThu tk)
        {
            db.Insert(tk);
        }
    }
}
